<?php

class Admin_Model_Users extends Zend_Db_Table_Abstract
{
    protected $_name="users";
    protected $_primary="id";
    
    var $id, $username, $password, $realname;
    
    public function getAll(){
        return $this->fetchall()->toArray();
    }
    
    public function getUserByUsername(){
    	return $this->fetchall("username='". $this->username ."'")->toArray();
    }
    
	public function getUserById(){
    	return $this->fetchall("id='". $this->id ."'")->toArray();
    }
    
    public function addUser()
    {
    	$data = array(
    		"username" => $this->username,
    		"password" => $this->password,
    		"realname" => $this->realname
    	);
    	$this->insert($data);
    }
    
    public function deleteUser(){
    	$this->delete("id='" . $this->id ."'");
    }
    
    public function updateUser()
    {
    	if($this->password!="")
    		$data['password'] = md5($this->password);
    		 
    	$data["realname"] = $this->realname;
    	
        $where="id='$this->id'";
        $this->update($data, $where);
    }
}

